<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信支付样例</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<body>
<div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式二</div>
<br/>
<img alt="模式二扫码支付" src="{$pic}" style="width:150px;height:150px;"/>
<div id="myDiv"></div>
<div id="timer">0</div>


</body>
<script>
    //设置每隔1000毫秒执行一次load() 方法
    var myIntval=setInterval(function(){load2()},1000);
    function load2(){
        document.getElementById("timer").innerHTML=parseInt(document.getElementById("timer").innerHTML)+1;
        var xmlhttp;
        if (window.XMLHttpRequest){
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }else{
            // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                trade_state=xmlhttp.responseText;
                if(trade_state=='SUCCESS'){
                    document.getElementById("myDiv").innerHTML='支付成功';
                    //alert(transaction_id);
                    //延迟3000毫秒执行tz() 方法
                    clearInterval(myIntval);
                    setTimeout("location.href='{:url(\"index/index/success\")}'",3000);

                }else if(trade_state=='REFUND'){
                    document.getElementById("myDiv").innerHTML='转入退款';
                    clearInterval(myIntval);
                }else if(trade_state=='NOTPAY'){
                    document.getElementById("myDiv").innerHTML='请扫码支付';

                }else if(trade_state=='CLOSED'){
                    document.getElementById("myDiv").innerHTML='已关闭';
                    clearInterval(myIntval);
                }else if(trade_state=='REVOKED'){
                    document.getElementById("myDiv").innerHTML='已撤销';
                    clearInterval(myIntval);
                }else if(trade_state=='USERPAYING'){
                    document.getElementById("myDiv").innerHTML='用户支付中';
                }else if(trade_state=='PAYERROR'){
                    document.getElementById("myDiv").innerHTML='支付失败';
                    clearInterval(myIntval);
                }

            }
        }
        //orderquery.php 文件返回订单状态，通过订单状态确定支付状态
        xmlhttp.open("POST","{:url('index/index/orderquery')}",false);
        //下面这句话必须有
        //把标签/值对添加到要发送的头文件。
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("out_trade_no={$num}");

    }
</script>

</html>